package com.webproject.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web config
 * 配置启用拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenHandlerInterceptor tokenHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //增加自定义拦截方法
        registry.addInterceptor(tokenHandlerInterceptor)
                .excludePathPatterns("/api/auth/**")  //跳过认证的路径
                .addPathPatterns("/api/**"); // 拦截认证的路径
    }
}
